package brad.zimmerman.dungeon.game;

import java.util.ArrayList;
import java.util.Random;

import android.graphics.PointF;

public class ClassAnimation {
	
	ArrayList<slopeAwesome> shroudMana;
	ArrayList<slopeAwesome> shroudHealth;
	ArrayList<slopeAwesome> rippleAnimation;
	ArrayList<slopeAwesome> deathBubbles;
	ArrayList<slopeAwesome> damageAnimation;
	ArrayList<slopeAwesome> moveDown;
	
	ClassAnimation(){
		this.shroudMana = new ArrayList<slopeAwesome>();
		this.shroudHealth = new ArrayList<slopeAwesome>();
		this.rippleAnimation = new ArrayList<slopeAwesome>();
		this.deathBubbles = new ArrayList<slopeAwesome>();
		this.damageAnimation = new ArrayList<slopeAwesome>();
		this.moveDown = new ArrayList<slopeAwesome>();
	}
	
	public void addAnimatedShroud(int X, int Y, int type){
		switch (type){
			case 0:this.shroudMana.add(new slopeAwesome(X,Y));break;
			case 1:this.shroudHealth.add(new slopeAwesome(X,Y));break;
		}
	}
	
	public void addmoveDown(int startY, int endY,int pic){
		this.moveDown.add(new slopeAwesome(startY,endY,pic));
	}
	
	public void addDamageAnimation(int X, int Y, int color, String word, int size, boolean unZoom){
		this.damageAnimation.add(new slopeAwesome(X,Y,color,word, size, unZoom));
	}
	
	public void addKillBubbles(int X, int Y, int color){
		for (int i = -6;i<=6;i+=6){
			this.deathBubbles.add(new slopeAwesome(X+i,Y,color));
		}
	}
	public void addKillBubbles(int X, int Y, int color, boolean zoomnozoom){
		for (int i = -6;i<=6;i+=6){
			this.deathBubbles.add(0,new slopeAwesome(X+i,Y,color,zoomnozoom));
		}
	}
	public void addKillBubbles(int X, int Y, int color, boolean zoomnozoom, int destX, int destY){
		for (int i = -6;i<=6;i+=6){
			this.deathBubbles.add(new slopeAwesome(X+i,Y,color,zoomnozoom,destX,destY));
		}
	}
	public void addRippleAnimation(int X, int Y,int color){
			this.rippleAnimation.add(new slopeAwesome(X,Y,color));
	}
	
	public void addRippleAnimation(int X, int Y,int color,boolean zoomnozoom){
		this.rippleAnimation.add(new slopeAwesome(X,Y,color,zoomnozoom));
}
	
	public void moveRipple(){
		for (int i = 0;i<this.rippleAnimation.size();i++){
			this.rippleAnimation.get(i).incrementPercent(10);
			if (this.rippleAnimation.get(i)._percent>=100){
				this.rippleAnimation.remove(i);
			}
		}
	}
	
	public void moveDownAnimation(){
		for (int i = 0;i<this.moveDown.size();i++){
			this.moveDown.get(i).moveDown();
			if (this.moveDown.get(i)._percent>=100){
				this.moveDown.remove(i);
			}
		}
	}
	
	public void moveAnimatedShroud(int destX, int destY, int type){
		switch(type){
			case 0:
				for (int i = 0;i<this.shroudMana.size();i++){
					this.shroudMana.get(i).moveCloserBalls(destX, destY);
					if (this.shroudMana.get(i)._percent>=100){
						this.shroudMana.remove(i);
					}
				}
				break;
			case 1:
				for (int i = 0;i<this.shroudHealth.size();i++){
					this.shroudHealth.get(i).moveCloserBalls(destX, destY);
					if (this.shroudHealth.get(i)._percent>=100){
						this.shroudHealth.remove(i);
					}
				}
				break;
			case 2:
				for (int i = 0;i<this.deathBubbles.size();i++){
					//Type is used in this case as a top barrier just in case
					this.deathBubbles.get(i).moveDeathBalls();
					if (this.deathBubbles.get(i)._percent>=100){
						this.deathBubbles.remove(i);
					}
				}
				break;
			case 3:
				for (int i = 0;i<this.damageAnimation.size();i++){
					//Type is used in this case as a top barrier just in case
					this.damageAnimation.get(i).moveDeathBallsFaster();
					if (this.damageAnimation.get(i)._percent>=100){
						this.damageAnimation.remove(i);
					}
				}
				break;
			default: break;
		}
	}
	
	class slopeAwesome {
		int _startX,_startY;
		int _currentX,_currentY;
		int _destX = -1, _destY = -1;
		float _percent;
		int color;
		String word;
		boolean unZoom;
		int size = 0;
		slopeAwesome(int posX, int posY){
			this._startX = posX;
			this._startY = posY;
			this._currentX = posX;
			this._currentY = posY;
			this._percent = 0;
			this.color = 0;
			this.word = "";
			this.unZoom = false;
		}
		slopeAwesome(int posX, int posY,int color){
			this._startX = posX;
			this._startY = posY;
			this._currentX = posX;
			this._currentY = posY;
			this._percent = 0;
			this.color = color;
			this.word = "";
			this.unZoom = false;
		}
		slopeAwesome(int posX, int posY,int color,boolean unZoom){
			this._startX = posX;
			this._startY = posY;
			this._currentX = posX;
			this._currentY = posY;
			this._percent = 0;
			this.color = color;
			this.word = "";
			this.unZoom = unZoom;
		}
		slopeAwesome(int posX, int posY,int color, String word, int size, boolean unZoom){
			this._currentX = posX;
			this._currentY = posY;
			this._percent = 0;
			this.color = color;
			this.word = word;
			this.unZoom = unZoom;
			this.size = size;
		}
		slopeAwesome(int posX, int posY,int color, boolean unZoom, int destX, int destY){
			this._startX = posX;
			this._startY = posY;
			this._currentX = posX;
			this._currentY = posY;
			this._percent = 0;
			this.color = color;
			this.unZoom = unZoom;
			_destX = destX;
			_destY = destY;
		}
		public void moveCloserBalls(int _destX, int _destY){
			this._currentX = (int) (this._startX + ((_destX - this._startX) * (this._percent/100)));
			this._currentY = (int) (this._startY + ((_destY - this._startY) * (this._percent/100)));
			//System.out.println(_currentX + " " + _currentY + " " + _startX + " " + _startY + " " + _destX + " " + _destY);
			if(this._percent<10){this._percent+=.05;}
			if(this._percent<20){this._percent+=2;}
			if(this._percent<40){this._percent+=5;}
			if(this._percent>40){this._percent+=10;}
		}
		public void moveDeathBalls(){
			Random random = new Random(System.currentTimeMillis());
			int movX = random.nextInt( 2 )+1;
			int movY = random.nextInt( 2 )+1;
			int sign = random.nextInt( 3 )-1;
			this._currentX += (movX*sign);
			this._currentY -= (movY);
			this._percent+=5;
		}
		public void moveDown(){
			_currentX = _startX + (int) (((float)_startY - (float)_startX) * (float)this._percent/(float)100);
			this._percent+=5;
		}
		public void moveDeathBallsFaster(){
			Random random = new Random(System.currentTimeMillis());
			int movX = random.nextInt( 2 )+1;
			int movY = random.nextInt( 2 )+1;
			int sign = random.nextInt( 3 )-1;
			this._currentX += (movX*sign);
			this._currentY -= (movY);
			this._percent+=10;
		}
		
		public void incrementPercent(int increment){
			this._percent += increment;
		}
	}
}
